<template>
	<el-container>
		<el-header class="header-tabs">
			<el-tabs type="border-card" @tab-click="tabClick">
				<el-tab-pane label="敏感信息设置"></el-tab-pane>
				<el-tab-pane label="IP访问黑名单"></el-tab-pane>
				<el-tab-pane label="上传文件白名单"></el-tab-pane>
				<el-tab-pane label="上传文件黑名单"></el-tab-pane>
			</el-tabs>
		</el-header>
		<el-main class="nopadding safety-main" v-show="tabIndex == 0">
			<el-alert
				title="敏感关键字（使用英文逗号分隔）"
				type="info"
                :closable="false"
				show-icon
			></el-alert>
			<el-input
				v-model="model.sensitive"
				type="textarea"
				:autosize="{ minRows: 8, maxRows: 15 }"
				placeholder="请输入内容"
			></el-input>
			<el-button
				type="primary"
				icon="el-icon-setting"
				style="margin-top: 10px"
                :loading="isSaveing"
				@click="saveSetting"
			>
				确定保存
			</el-button>
		</el-main>
        <el-main class="nopadding safety-main" v-show="tabIndex == 1">
			<el-alert
				title="设置IP黑名单，不设置全部可访问，如设置IP后，设置的IP不可访问（注：设置IP方式为一行一个IP地址）"
				type="info"
                :closable="false"
				show-icon
			></el-alert>
			<el-input
				v-model="model.ipLimit"
				type="textarea"
				:autosize="{ minRows: 8, maxRows: 15 }"
				placeholder="设置IP方式为一行一个IP地址"
			></el-input>
			<el-button
				type="primary"
				icon="el-icon-setting"
				style="margin-top: 10px"
                :loading="isSaveing"
				@click="saveSetting"
			>
				确定保存
			</el-button>
		</el-main>
        <el-main class="nopadding safety-main" v-show="tabIndex == 2">
			<el-alert
				title="设置只允许上传文件的后缀名，格式为：”jpg|gig“，以竖线分隔，支持多个后缀名"
				type="info"
                :closable="false"
				show-icon
			></el-alert>
			<el-input
				v-model="model.uploadWhite"
				type="textarea"
				:autosize="{ minRows: 8, maxRows: 15 }"
				placeholder="格式为：”jpg|gig“，以竖线分隔"
			></el-input>
			<el-button
				type="primary"
				icon="el-icon-setting"
				style="margin-top: 10px"
                :loading="isSaveing"
				@click="saveSetting"
			>
				确定保存
			</el-button>
		</el-main>
        <el-main class="nopadding safety-main" v-show="tabIndex == 3">
			<el-alert
				title="设置不允许上传的文件后缀名，优先级高于白名单，格式为：”jpg|gig“，以竖线分隔，支持多个后缀名"
				type="info"
                :closable="false"
				show-icon
			></el-alert>
			<el-input
				v-model="model.uploadBlack"
				type="textarea"
				:autosize="{ minRows: 8, maxRows: 15 }"
				placeholder="格式为：”jpg|gig“，以竖线分隔"
			></el-input>
			<el-button
				type="primary"
				icon="el-icon-setting"
				style="margin-top: 10px"
                :loading="isSaveing"
				@click="saveSetting"
			>
				确定保存
			</el-button>
		</el-main>
	</el-container>
</template>
<script>
export default {
	data() {
		return {
			tabIndex: 0,
            isSaveing: false,
			model: {
				sensitive: undefined,
				ipLimit: undefined,
				uploadWhite: undefined,
				uploadBlack: undefined,
			},
		};
	},
    mounted() {
        this.init()
    },
	methods: {
        async init(){
            var res=await this.$API.syssafety.model.get();
            if(res.code!=200){
                this.$message.error(res.message);
                return
            }
            this.model=res.data
        },
		tabClick(tab) {
			console.log(tab.index);
			this.tabIndex = tab.index;
		},
        async saveSetting(){
            this.isSaveing = true;
            var res=await this.$API.syssafety.save.post(this.model);
            if(res.code!=200){
                this.$message.error(res.message);
                return
            }
            this.$message.success("保存成功");
        }
	},
};
</script>
<style>
.el-main.safety-main {
	padding: 20px;
}
</style>
